package com.tools;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LeetTest {

	public static void main(String[] args) {
		System.out.println(question4(123));
	}
	/**
	 * Given a 32-bit signed integer, reverse digits of an integer.

		Example 1:
		
		Input: 123
		Output: 321
		Example 2:
		
		Input: -123
		Output: -321
		Example 3:
		
		Input: 120
		Output: 21
	 */
	private static int question4(int num) {
		int abs=Math.abs(num);
		if(abs<10&&abs>=0) return num;
		StringBuilder res=new StringBuilder();
		while(abs>=1) {
			int a=abs%10;
			res.append(a);
			abs=abs/10;
		}
		return (Math.abs(num)/num)*Integer.parseInt(res.toString());
	}

	/**
	 * For example, given array S = {1 0 -1 0 -2 2}, and target = 0.
    A solution set is:
    (-1,  0, 0, 1)
    (-2, -1, 1, 2)
    (-2,  0, 0, 2)
 
	 */
	private static void question3() {
		int[] nums = {1,0 ,-1, 0, -2, 2};
		int target=0;
		List<List<Integer>> res=new ArrayList<List<Integer>>();
		for (int i = 0; i < nums.length; i++) {
			for (int j = 0; j < nums.length; j++) {
				for (int k = 0; k < nums.length; k++) {
					for (int m = 0; m < nums.length; m++) {
						if((i!=j)&&(i!=k)&&(i!=m)&&(j!=k)&&(j!=m)&&(k!=m)) {
							if(nums[i]+nums[j]+nums[k]+nums[m]==target) {
								if(!exits(res,nums[i],nums[j],nums[k],nums[m])) {
									res.add(Arrays.asList(nums[i],nums[j],nums[k],nums[m]));
								}
							}
						}
					}
				}
			}
		}
		for (List<Integer> list : res) {
			System.out.println(list);
		}
		
	}
	private static boolean exits(List<List<Integer>> res, int i, int j, int k, int l) {
		for (List<Integer> list : res) {
			if(list.contains(i)&&list.contains(j)&&list.contains(k)&&list.contains(l)) {
				return true;
			}
		}
		return false;
	}

	/**
	 *  For example, given array S = {-1 0 1 2 -1 -4},
	    A solution set is:
	    (-1, 0, 1)
	    (-1, -1, 2)
	 */
	private static void question2() {
		int[] nums = {-1, 0 ,1 ,2 ,-1 ,-4 };
		List<List<Integer>> res=new ArrayList<List<Integer>>();
		for (int i = 0; i < nums.length; i++) {
			for (int j = 0; j < nums.length; j++) {
				for (int k = 0; k < nums.length; k++) {
					if((i!=j)&&(i!=k)&&(j!=k)) {
						if(nums[i]+nums[j]+nums[k]==0) {
							if(!exits(res,nums[i],nums[j],nums[k])) {
								res.add(Arrays.asList(nums[i],nums[j],nums[k]));
							}
						}
					}
				}
			}
		}
		for (List<Integer> list : res) {
			System.out.println(list);
		}
		
	}

	private static boolean exits(List<List<Integer>> res, int i, int j, int k) {
		for (List<Integer> list : res) {
			if(list.contains(i)&&list.contains(j)&&list.contains(k)) {
				return true;
			}
		}
		return false;
	}
	/**
	 * Example:
	 * 
	 * Given nums = [2, 7, 11, 15], target = 9,
	 * 
	 * Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].
	 */
	public static void question1() {
		int[] nums = { 2, 7, 11, 15 };
		int target = 18;
		List<Integer> res = new ArrayList<Integer>();
		for (int i = 0; i < nums.length; i++) {
			for (int j = 0; j < nums.length; j++) {
				if(nums[i] == nums[j]) {
					continue;
				}
                int temp=nums[i]+nums[j];
                if(target == temp) {
                	res.add(i);
                }
			}
		}
		System.out.println(res);
	}
}
